package viewmodel;

import java.util.List;

import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Messagebox;

import admin.dao.VideoDAO;

public class VideoDataVM {
	
	private List<VideoEditStatus> videoEditData;
	private List<VideoTypeModel> typeData;
	private boolean displayEdit = true;
	
	public VideoDataVM(){
		videoEditData = new VideoDataModel().convertVideoToEditData();
		typeData = VideoTypeModel.createTypeList();
	}

	public List<VideoEditStatus> getVideoEditData() {
		return videoEditData;
	}

	public void setVideoEditData(List<VideoEditStatus> videoEditData) {
		this.videoEditData = videoEditData;
	}

	public List<VideoTypeModel> getTypeData() {
		return typeData;
	}

	public void setTypeData(List<VideoTypeModel> typeData) {
		this.typeData = typeData;
	}

	public boolean isDisplayEdit() {
		return displayEdit;
	}

	public void setDisplayEdit(boolean displayEdit) {
		this.displayEdit = displayEdit;
	}
	@Command
	public void delVideo(@BindingParam("videoEditStatus") VideoEditStatus ves){
					VideoDAO.removeVideo(ves.getVideo());
					videoEditData.remove(ves);
					refreshRowTemplate(ves);
	}
	@Command
	public void changeEditableStatus(@BindingParam("videoEditStatus") VideoEditStatus ves){
		ves.setEditingStatus(!ves.getEditingStatus());
		refreshRowTemplate(ves);
	}
	@Command
	public void confirm(@BindingParam("videoEditStatus")VideoEditStatus ves){
		changeEditableStatus(ves);
		VideoDAO.updateVideo(ves);
		refreshRowTemplate(ves);
	}
	public void refreshRowTemplate(VideoEditStatus videoEditData){
		BindUtils.postNotifyChange(null, null, videoEditData, "editingStatus");
	}
	}
